package demo.com.thread.service;

import demo.com.thread.dto.Demo;

public class ThreadlocalTest {

    ThreadLocal<Demo> threadLocal = new ThreadLocal<>();

    /**
     * 结论ThreadLocal.get 给的是内存地址。对get结果进行操作会直接影响到结果。
     */
    public static void main(String[] args) {
        ThreadlocalTest threadlocalTest = new ThreadlocalTest();
        Demo demo = new Demo();
        demo.setNum(1);
        threadlocalTest.threadLocal.set(demo);
        System.out.println(threadlocalTest.threadLocal.get().getNum());
        Demo demo1 = threadlocalTest.threadLocal.get();
        demo1.setNum(11);
        threadlocalTest.threadLocal.get().setNum(threadlocalTest.threadLocal.get().getNum() + 1);
        System.out.println(demo1.getNum());
    }

}
